package com.example.bai12;

import java.util.ArrayList;

import com.example.adapter.PhongBanAdapter;
import com.example.object.NhanVien;
import com.example.object.PhongBan;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;

public class ChuyenPhongBanActivity extends Activity{
	
	ImageButton btnok;
	ListView listpb;
	ArrayList<PhongBan> arr;
	PhongBanAdapter adapter;
	NhanVien nv=null;
	PhongBan pbselect=null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chuyen_phong_ban);
		getControls();
		addEvents();
	}
	
	private void getControls()
	{
		btnok= (ImageButton) findViewById(R.id.btnok);
		listpb= (ListView) findViewById(R.id.listpb);
		arr= MainActivity.getArr();
		adapter= new PhongBanAdapter(this, android.R.layout.simple_list_item_single_choice, arr);
		listpb.setAdapter(adapter);
		
		//get data
		Intent i= getIntent();
		Bundle b= i.getBundleExtra("DATA");
		 nv= (NhanVien) b.getSerializable("NHANVIEN");
		
	}
	private void addEvents()
	{
		btnok.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(pbselect!=null)
				{
					pbselect.upsertNhanVien(nv);
					setResult(MainActivity.CHUYEN_PHONG_THANH_CONG);
					finish();
				}
			}
		});
		listpb.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				pbselect=arr.get(arg2);
			}
		});
		
	}
}
